#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
typedef struct Lnode
{
	int data;
	struct Lnode* next;
}Lnode, * Linklist;

void Initlist(Linklist* l)
{
	(*l) = (Linklist)malloc(sizeof(Lnode));
	(*l)->next = NULL;
}
void Creatlist(Linklist* l, int n)
{
	int i;
	Linklist p,r;
	r = (*l);
	for (i = 1; i < n; i++)
	{
		p = (Linklist)malloc(sizeof(Lnode));
		r->data = i;
		r->next = p;
		p->next = (*l);
		p->data = i + 1;
		r = p;
	}
}
int Locate_and_delete(Linklist L)
{
	int count = 1;
	Linklist p = L;
	Linklist w = NULL;
	while (p->next != p)
	{
		if ((count+1)% 3 == 0)
		{	
			w = p;
		}
		if (count % 3 == 0)
		{
			Linklist q = p;
			w->next = p->next;
			count++;
			p = p->next;
			free(q);
			continue;
		}
		count++;
		p = p->next;
	}
	return p->data;
}
int main()
{
	int n;
	scanf("%d", &n);
	Linklist L = NULL;
	Initlist(&L);
	Creatlist(&L, n);
	int ret=Locate_and_delete(L);
	printf("%d", ret);
	return 0;
}